<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    ul {
        width: 100px;
    }

    li {
        background-color: rgb(111, 171, 223);
        position: relative;
        width: 100px;
    }

    a {
        color: red;
        float: right;
    }
</style>

<body>
    <div class="main">
        <div class="mycon">
            <input type="text">
            <button class="btn1">发布</button>
            <button class="btn2">删除</button>
            <button class="clone">复制</button>
        </div>
        <ul class="bgcon">
        </ul>
    </div>
    <script>
        var input = document.querySelector('input');
        var btn1 = document.querySelector('.btn1');
        var btn2 = document.querySelector('.btn2');
        var bgcon = document.querySelector('ul');
        var clone = document.querySelector('.clone');
        btn1.onclick = function () {
            // console.log(input.value);
            if (input.value.length == 0) {
                return false;
            } else {
                var myli = document.createElement('li');
                myli.innerHTML = input.value + "<a href='javascript:;'>删除</a>"
                bgcon.appendChild(myli);
                input.value = "";
                var as = document.querySelectorAll('a');
                for (var i = 0; i < as.length; i++) {
                    as[i].onclick = function () {
                        bgcon.removeChild(this.parentNode);
                    }
                }
            }


        }
        btn2.onclick = function () {
            if (bgcon.children.length > 0) {
                bgcon.removeChild(bgcon.children[0]);
            }
        }
        clone.onclick = function () {
            if (bgcon.children.length > 0) {
                bgcon.children[0].cloneNode();
                bgcon.appendChild(bgcon.children[0].cloneNode(true));
            }
        }
    </script>
</body>

</html>